<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Blog/classes/PhpFox_ComponentMyPageBlogs.class.php, $Author:  $ */



/** Component for showing blogs of any member
 *
 * @version $Id: PhpFox_ComponentMyPageBlogs.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 * @package module.blog
 */
class PhpFox_Mod_Blog_ComponentMyPageBlogs extends BaseComponent
{
    function process()
    {
        $oBlogItem = $this->_oModule->getItem('Blog');
        /* @var $oBlogItem PhpFox_Mod_Blog_ItemBlog */
        $oSecurityService = App::getModuleService('Account', 'Security');
        /* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
        $oReq = &App::getRequest();
        $oUrl = &App::getUrl();
        $oTpl = $this->_oModule->getTemplate();
        App::loadClass('Pager');
        $iUserId = $this->getParam('userId');
        if ( !$iUserId )
        {
        	return '';
        }
        $oSecurityService->checkPerm('blog', array('read_only', 'full'));
        $oSecurityService->checkAccess('blogs');
        $sCurrentUser = $oSecurityService->getCurrentUserLogin();
        $sUser = $oReq->get('name');
        $iPage = $oReq->getInt('page', 1);
        $iPageSize = App::getParam('public.pagesize');
        $sSort = 'time DESC';
        $aCond = array();
        $aCond['user_id'] = '= "'. $iUserId .'"';
        list($aItems, $iCnt) = $oBlogItem->getList($aCond, $iPage, $iPageSize, $sSort, '', '', 'j.id, j.user_id, j.title, j.text, j.time, j.comment, j.tags, u.user', array("". App::getT('user') ." AS u ON(j.user_id = u.id)"));
		$oPager = &new Pager($iCnt, $iPage, $iPageSize);
        $iFrom = $oPager->getOffset($iPage, $iPageSize);
        $iTo = (($iFrom + $iPageSize) > $iCnt) ? $iCnt : ($iFrom + $iPageSize);

        $oTpl->assignSrc('aItems', $aItems);
        $oTpl->assign(array(
        	'iCnt'           => $iCnt,
        	'bCanComment'    => $oSecurityService->checkPerm('blog', array('full'), false),
            'aPaging'        => ($iCnt) ? $oPager->getInfo($oUrl) : '',
        	'iFrom'          => ($iCnt) ? ($iFrom + 1) : 0,
        	'iTo'            => $iTo,
        ));
        return $oTpl->fetch('MyPageBlogs.html');
    }
}
?>